package com.example.iconmaker;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;


public class Rect2D {

	private int drawMode = GL10.GL_TRIANGLE_FAN;
	public float left;
	public float top;
	public float right;
	public float bottom;
	private float[] quaterVertices;
	private FloatBuffer quaterBuffer;
	
	public Rect2D(float left, float top, float right, float bottom) {
		super();
		this.left = left;
		this.top = top;
		this.right = right;
		this.bottom = bottom;
		float[] q = {
			left , bottom,
			left , top,
			right, top,
			right, bottom
		};
		quaterVertices = q;
		ByteBuffer qbb = ByteBuffer.allocateDirect(quaterVertices.length * 4);
		qbb.order(ByteOrder.nativeOrder());
		quaterBuffer = qbb.asFloatBuffer();
		quaterBuffer.put(quaterVertices);
		quaterBuffer.position(0);
	}

	public void draw(GL10 gl){
		gl.glVertexPointer(2, GL10.GL_FLOAT, 0, quaterBuffer);
		gl.glDrawArrays(drawMode, 0, 4);
	}
}
